<?php
/**
 * 会员接口控制器
 */
namespace app\manage\controller\member;

use app\manage\controller\Base;
use app\common\query\Member as MemberQuery;

class Api extends Base
{
	/**
	 * 查询会员分页
	 * @return [type] [description]
	 */
	public function member_rows(){
		$params = $this->request->param();

        $perpagenum = isset($params['limit'])?intval($params['limit']):15;
        $perpagenum = $perpagenum>100?100:$perpagenum;
        $page = isset($params['page'])?intval($params['page']):1;
        $page = $page<1?1:$page;

        unset($params['limit']);
        unset($params['page']);
        $where = [];
        if(isset($params['key'])){
            $where= parseWhere($params['key'],true);
        }

        $data = model('member')->getPageDatas($where,$page,$perpagenum);
        $data['code'] = 1;
        return json($data);
	}
	/**
	 * 按id查询单个会员
	 * @return [type] [description]
	 */
	public function member_row(){
		$params = $this->request->param();
		$id = isset($params['id'])?intval($params['id']):0;
		if(!$id)
			return json(['code'=>0,'msg'=>'参数错误']);;
		$data = model('member')->getOneDataById($id);
		return json(['code'=>1,'msg'=>'查询成功','data'=>$data]);
	}

	/**
	 * 会员状态接口
	 * @return [type] [description]
	 */
	public function member_status(){
		$params = $this->request->param();
		$statusId = isset($params['id'])?$params['id']:null;

		$data = model('member')::status($statusId);
		return json($data);
	}

	/**
	 * 是否代理中心
	 * @return [type] [description]
	 */
	public function member_is_agent(){
		$params = $this->request->param();
		$key = isset($params['id'])?$params['id']:null;

		$data = model('member')::is_agent($key);
		return json($data);
	}

	/**
	 * 会员大区
	 * @return [type] [description]
	 */
	public function member_area(){
		$params = $this->request->param();
		$key = isset($params['id'])?$params['id']:null;

		$data = model('member')::area($key);
		return json($data);
	}
	/**
	 * 会员类型
	 * @return [type] [description]
	 */
	public function member_type(){
		$params = $this->request->param();
		$key = isset($params['id'])?$params['id']:null;

		$data = model('member')::type($key);
		return json($data);
	}
	/**
	 * 手机验证状态
	 * @return [type] [description]
	 */
	public function member_is_phone_checked(){
		$params = $this->request->param();
		$key = isset($params['id'])?$params['id']:null;

		$data = model('member')::is_phone_checked($key);
		return json($data);
	}

	/**
	 * 地址接口
	 * @return [type] [description]
	 */
	public function city(){
		$params = $this->request->param();
		$id = isset($params['id'])?$params['id']:'001';

		$data = model('city')::findByParent($id);
		return json($data);
	}

	/**
	 * 会员网络图
	 * @return [type] [description]
	 */
	public function member_map(){
		$params = $this->request->param();
		$uid = isset($params['mid'])?$params['mid']:'';
		if(!$uid)
			$uid = 1;

		$data = model('member')->queryMap($uid);
		return json(['code'=>1,'msg'=>'查询成功','data'=>$data]);

	}


}